﻿using Microsoft.AspNetCore.Mvc;
using PmSoft.Core;
using PmSoft.Core.Domain.Auth;
using PmSoft.Web.Abstractions;
using PmSoft.Web.Abstractions.Attributes;
using Demo.PetaPoco.Application.Services.User;

namespace Demo.PetaPoco.WebApi.Controllers;

/// <summary>
/// 用户管理控制器
/// </summary>
/// <param name="userService">用户服务</param>
/// <param name="applicationContext">应用程序上下文</param>
[Route("api/[controller]")]
[ApiController]
[RestrictAccess(allowedTenantTypes: ["SysUser"])]
public class UserController(UserService userService,
	IApplicationContext applicationContext) : ControllerBase
{
	/// <summary>
	/// 获取当前用户信息
	/// </summary>
	/// <returns></returns>

	[HttpGet("info")]
	public async Task<IApiResult> GetUserInfoAsync()
	{
		IAuthedUser authUser = applicationContext.RequiredCurrentUser;
		var userInfoDto = await userService.GetAuthedUserInfoAsync(authUser);
		return ApiResult.Ok(userInfoDto);
	}
 
}
